<!-- 信息登记页面 -->
<template>
  <div>
    <van-nav-bar fixed left-arrow placeholder title="登记" @click-left="onClickLeft" />
    <div class="info">
      <div class="infoCon" @click="handleClick('基本信息')">
        <div class="left">
          <span>基本信息</span>
        </div>
        <image v-if="isBasicOk" class="right" src="/package-guest/static/info/ok.png" />
        <image v-if="!isBasicOk" class="right" src="/package-guest/static/me/arrow-right.png" />
      </div>
      <div class="infoCon" @click="handleClick('个人信息')">
        <div class="left">
          <span>个人信息</span>
        </div>
        <image v-if="isPersonOk" class="right" src="/package-guest/static/info/ok.png" />
        <image v-if="!isPersonOk" class="right" src="/package-guest/static/me/arrow-right.png" />
      </div>
      <div class="infoCon" @click="handleClick('家庭成员')">
        <div class="left">
          <span>家庭成员</span>
        </div>
        <image v-if="familyList.length>0" class="right" src="/package-guest/static/info/ok.png" />
        <image v-else class="right" src="/package-guest/static/me/arrow-right.png" />
      </div>
      <div class="infoCon" @click="handleClick('主要工作经历')">
        <div class="left">
          <span>主要工作经历</span>
        </div>
        <image v-if="workList.length>0" class="right" src="/package-guest/static/info/ok.png" />
        <image v-else class="right" src="/package-guest/static/me/arrow-right.png" />
      </div>
      <div class="infoCon" @click="handleClick('教育及培训')">
        <div class="left">
          <span>教育及培训</span>
        </div>
        <image v-if="educatList.length>0" class="right" src="/package-guest/static/info/ok.png" />
        <image v-else class="right" src="/package-guest/static/me/arrow-right.png" />
      </div>
      <div class="infoCon" @click="handleClick('自我评价')">
        <div class="left">
          <span>自我评价</span>
        </div>
        <image v-if="showSelf" class="right" src="/package-guest/static/info/ok.png" />
        <image v-else class="right" src="/package-guest/static/me/arrow-right.png" />
      </div>
      <!-- <div v-for="item in info" :key="item.name" class="infoCon" @click="handleClick(item)">
        <div class="left">
          <span>{{ item.name }}</span>
        </div>
        <image class="right" src="/package-guest/static/me/arrow-right.png" />
      </div> -->
    </div>
    <div class="infoBtn">
      <van-button size="large" :disabled="showSubmit" :class="showSubmit?'noSubmit':'submit'" round @click="submitForm">
        确认并提交
      </van-button>
    </div>
    <van-toast id="van-toast" />
  </div>
</template>
<script>
import { submitInfo } from '@/apis/guest/recruit'
import Toast from '@/wxcomponents/vant/toast/toast'
export default {
  components: { },
  onLoad(option) {
    if (option.selfInfo) {
      this.selfInfos = option.selfInfo
      this.showSelf = true
      console.log(this.selfInfos, 'this.selfInfo')
    }
  },
  onShow() {
    const person = uni.getStorageSync('person')
    if (person) {
      this.isPersonOk = person.isPersonOk
      this.personForm = person
    }
    const basic = uni.getStorageSync('basic')
    console.log(basic, 'basic')
    console.log(basic.isBasicOk, 'basic.isBasicOk')
    if (basic) {
      this.isBasicOk = basic.isBasicOk
      this.basicForm = basic
    }
    this.familyList = uni.getStorageSync('family')
    this.workList = uni.getStorageSync('work')
    this.educatList = uni.getStorageSync('educat')
  },
  data() {
    return {
      showSubmit: true,
      isBasicOk: false,
      isPersonOk: false,
      showSelf: false,
      info: [
        { name: '基本信息' },
        { name: '个人信息' },
        { name: '家庭成员' },
        { name: '主要工作经历' },
        { name: '教育及培训' },
        { name: '自我评价' },
      ],
      basicForm: {},
      personForm: {},
      familyList: [],
      workList: [],
      educatList: [],
      selfInfos: '',
    }
  },
  mounted() {
    if (this.isPersonOk && this.isBasicOk && this.selfInfos.trim().length > 0) {
      this.showSubmit = false
    }
  },
  methods: {
    // 返回上一页
    onClickLeft() {
      uni.navigateBack()
    },
    handleClick(item) {
      switch (item) {
        case '基本信息':
          uni.navigateTo({
            url: '/package-guest/pages/info-regist/basic-info/index',
          })
          break
        case '个人信息':
          uni.navigateTo({
            url: '/package-guest/pages/info-regist/person-info/index',
          })
          break
        case '家庭成员':
          uni.navigateTo({
            url: '/package-guest/pages/info-regist/family-members/index',
          })
          break
        case '主要工作经历':
          uni.navigateTo({
            url: '/package-guest/pages/info-regist/work-experience/index',
          })
          break
        case '教育及培训':
          uni.navigateTo({
            url: '/package-guest/pages/info-regist/educat-train/index',
          })
          break
        case '自我评价':
          uni.navigateTo({
            url: `/package-guest/pages/info-regist/self-evaluation/index?selfInfos=${this.selfInfos}`,
          })
          break
      }
    },
    async submitForm() {
      let newObj = {}
      newObj = { ...this.basicForm, ...this.personForm }
      if (this.familyList) {
        newObj.userFamilyMembers = this.familyList
      } else {
        newObj.userFamilyMembers = []
      }
      if (this.workList) {
        newObj.userWorkExperience = this.workList
      } else {
        newObj.userWorkExperience = []
      }
      if (this.educatList) {
        newObj.userEducationTraining = this.educatList
      } else {
        newObj.userEducationTraining = []
      }
      newObj.selfEvaluation = this.selfInfos
      const res = await submitInfo(newObj)
      if (res.code === 0) {
        Toast('提交成功')
        uni.removeStorageSync('basic')
        uni.removeStorageSync('person')
        uni.removeStorageSync('family')
        uni.removeStorageSync('educat')
        uni.removeStorageSync('work')
        uni.reLaunch({
          url: '/package-guest/pages/index/index',
        })
        // uni.reLaunch({
        //   url: `/package-guest/pages/info-regist/index`,
        // })
      } else {
        Toast('提交失败')
      }
    },
  },
}
</script>
<style lang="scss" scoped>
.info{
    margin-top: 15px;
    display: flex;
    flex-flow: column;
    align-items: center;
    .infoCon {
        width: 86%;
        margin-bottom: 10px;
        padding: 14px 10px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        box-shadow: 0px 0px 4px 0px rgba(0,0,0,0.06);
        border-radius: 2px;
        .left {
            display: flex;
            align-items: center;
            color: #333;
        }
        .right {
            width: 16px;
            height: 16px;
        }
    }
}
.infoBtn{
    text-align: center;
    padding-top: 15%;
}

</style>
<style lang="scss">
.infoBtn{
  .noSubmit{
    .van-button--round {
      height: 36px;
      width: 75%;
      background: #ccc !important;
      color: #fff !important;
      font-size: 16px !important;
    }
  }
  .submit{
    .van-button--round {
      height: 36px;
      width: 75%;
      background: #029b00!important;
      color: #fff !important;
      font-size: 16px !important;
    }
  }
}
</style>
